import Taro from '@tarojs/taro';

const initState = {
    tabBarID: 1,
    selectedYear: Taro.getStorageSync('selectedYear'),
    selectedMonth: Taro.getStorageSync('selectedMonth'),
    selectedDay: Taro.getStorageSync("selectedDay"),
    selectedStore: Taro.getStorageSync("selectedStore")
}

const reducer = (state = initState, action) => {
    switch (action.type){
        case 'SELECTEDSTORE':
            return {
                ...state,
                selectedStore:Taro.getStorageSync('selectedStore')
            }
        case 'SELECTEDMONTH':
            return {
                ...state,
                selectedMonth:Taro.getStorageSync('selectedMonth')
            }
        case 'SELECTEDDAY':
            return {
                ...state,
                selectedDay:Taro.getStorageSync('selectedDay')
            }

        case 'SELECTEDYEAR':
            return {
                ...state,
                selectedYear:Taro.getStorageSync('selectedYear')
            }
        case 'INDEX':
            return {
                ...state,
                tabBarID:1
            }
        case 'BOOK':
            return {
                ...state,
                tabBarID:2
            }
        case 'LIST':
            return {
                ...state,
                tabBarID:3
            }
        case 'STORE':
            return {
                ...state,
                tabBarID:4
            }
        case 'CENTER':
            return {
                ...state,
                tabBarID:5
            }
        default:
            return {
                ...state
            }
    }
}

export default reducer;